#include "Logger.h"

using namespace GalliumEngine;

Logger::Logger() : Singleton<Logger>()
{
}

Logger::~Logger()
{
}

void Logger::initialize(std::string fileName, bool enabled, bool date)
{
	isEnabled = enabled;

	if(isEnabled)
	{
		time_t rawtime;
		struct tm timeinfo;
		char buffer [80];

		time (&rawtime);
		localtime_s(&timeinfo,&rawtime);
		std::strftime(buffer,80,"-%H-%M-%S-%m-%d-%Y",&timeinfo);

		/*logFile = "../bin/";

		if(_DEBUG) { logFile += "Debug/"; }
		else { logFile += "Release/"; }
		logFile += fileName;
		if(_DEBUG) { logFile += "Debug"; }
		else { logFile += "Release"; }
		if(date) { logFile += buffer; }
		logFile += ".log";*/

		logFile = "";
		logFile += fileName;
		if(date) { logFile += buffer; }
		logFile += ".log";

		std::ofstream file;
		file.open(logFile.c_str(), std::ios::out);
		file << logFile << buffer << " Initialized" << "\n";
		file.close();		
	}
}

void Logger::write(std::string message)
{
	if(isEnabled)
	{
		std::ofstream file;
		file.open(logFile.c_str(), std::ios::out | std::ios::app); 

		if (file.is_open())
		{
			message += "\n";
			file << message;
			file.close();
		}
		
	}
}